package com.yedou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yedou.common.PageResult;
import com.yedou.entity.po.User;
import com.yedou.mapper.UserMapper;
import com.yedou.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    // 分页查询用户
    public PageResult<User> pageUser(Integer pageNum, Integer pageSize) {
        Page<User> page = new Page<>(pageNum, pageSize);
        IPage<User> userPage = baseMapper.selectPage(page, null);
        return PageResult.fromIPage(userPage);
    }

    // 带条件的分页查询
    public PageResult<User> pageUserByCondition(Integer pageNum, Integer pageSize, User query) {
        Page<User> page = new Page<>(pageNum, pageSize);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (query.getName() != null) {
            queryWrapper.like("name", query.getName());
        }
        // ... 其他条件
        IPage<User> userPage = baseMapper.selectPage(page, queryWrapper);
        return PageResult.fromIPage(userPage);
    }
    // 继承后自动获得CRUD能力，可重写或添加自定义方法
}